import os, pygame
from math import log
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((640, 400))
screen.fill((100, 100, 100))


land = pygame.image.load( os.path.abspath( "./resources" ) + '/hex_land.png' ).convert()
land.set_colorkey( (0x80,0x00,0x80), RLEACCEL )


def get_elevation_surface( color, size ):

    b = int(round( size[1] / 4.00 ))
    elev_band_sz = ( size[1] / 2, size[1] / 6 )
    s_stripe = pygame.Surface( elev_band_sz, flags=SRCALPHA )
    s_elev = pygame.Surface( size, flags=SRCALPHA )
    
    exp = log( 255.0, elev_band_sz[1] )

    for i in range( elev_band_sz[1] ):
        pygame.draw.line(s_stripe, ( color[0], color[1], color[2], int( (255-(i**exp)) ) ), (i/2 , i), (elev_band_sz[0] - i/2 , i))


    s_elev.blit( pygame.transform.rotate(s_stripe, 30), (0,0) )
    s_elev.blit( pygame.transform.rotate(s_stripe, 90), (0,b) )

    s_stripe_rot = pygame.transform.rotate(s_stripe, 150)
    x = s_elev.get_width() - s_stripe_rot.get_width()
    y = s_elev.get_height() - s_stripe_rot.get_height()
    s_elev.blit( s_stripe_rot, (0,y) )
    
    s_stripe_rot = pygame.transform.rotate(s_stripe, 210)
    x = s_elev.get_width() - s_stripe_rot.get_width()
    y = s_elev.get_height() - s_stripe_rot.get_height()
    s_elev.blit( s_stripe_rot, (x,y) )
    
    s_stripe_rot = pygame.transform.rotate(s_stripe, 270)
    x = s_elev.get_width() - s_stripe_rot.get_width()
    s_elev.blit( s_stripe_rot, (x,b) )
    
    s_stripe_rot = pygame.transform.rotate(s_stripe, 330)
    x = s_elev.get_width() - s_stripe_rot.get_width()
    s_elev.blit( s_stripe_rot, (x,0) )

    return s_elev



thick = 128
width = screen.get_width()
height = screen.get_height()

s_top = pygame.Surface( (width, thick), flags=SRCALPHA)
s_left = pygame.Surface( (thick, height), flags=SRCALPHA)

for i in range( thick ):
    pygame.draw.line(s_top, (255, 255, 255, (255-(i*2))), (0, i), (width, i))
    pygame.draw.line(s_left, (255, 255, 255, (255-(i*2))), (i,0), (i,width))

s_bot = pygame.transform.rotate(s_top, 180)
s_right = pygame.transform.rotate(s_left, 180)

screen.blit(s_top, (0, 0))
screen.blit(s_left, (0, 0))
screen.blit(s_bot, (0, height-s_bot.get_height()))
screen.blit(s_right, (width-s_right.get_width(), 0))


scale = land.get_width() * 2, land.get_height() * 2
new_land = pygame.transform.scale(land, scale)
screen.blit( new_land, (50,20))
screen.blit( get_elevation_surface( (0,0,80), new_land.get_size()), (50,20))


screen.blit( land, (150,120))
screen.blit( get_elevation_surface( (0,0,0), land.get_size()), (150,120))

scale = land.get_width() / 2, land.get_height() / 2

new_land = pygame.transform.scale(land, scale)
screen.blit( new_land, (250,220))
screen.blit( get_elevation_surface( (0,0,80), new_land.get_size()), (250,220))



pygame.display.flip()

while 1:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            pygame.quit()
